var t = getApp();

Page({
    data: {
        email: "",
        strpicname: "",
        Amount: "",
        contact: "",
        condition: !1,
        id: "",
        From: "",
        htbase: "",
        partAorB: "",
        conds: !0,
        showht: !0
    },
    onLoad: function(t) {
        this.setData({
            email: t.email,
            Amount: t.Amount,
            id: t.id,
            From: t.From,
            htbase: t.htbase,
            Price: t.Amount
        }), "undefined" != t.Amount && t.Amount || this.setData({
            conds: !1
        }), this.sessValid();
    },
    onShow: function() {
        var a = this.data.Amount;
        t.globalData.userInfo;
        "协商议价" == a && this.setData({
            condition: !0,
            Price: "noPrice"
        });
    },
    onReady: function() {
        this.data.Price;
    },
    sessValid: function() {
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/sessValid",
            data: {},
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                console.log(a.data), 0 == a.data && t.WxLogin();
            },
            fail: function(a) {
                t.WxLogin();
            }
        });
    },
    ORIsessValid: function() {
        var a = this;
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/sessValid",
            data: {},
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(e) {
                console.log(e.data), 0 == e.data && t.getWxLogin(function(e) {
                    console.log(e), wx.request({
                        url: t.url + "addon/Loginlog/Loginlog/gethtbi",
                        data: {},
                        method: "POST",
                        header: {
                            "content-type": "application/x-www-form-urlencoded",
                            Cookie: "PHPSESSID=" + e
                        },
                        success: function(t) {
                            console.log("有：", t), a.setData({
                                totalsum: t.data
                            }), t.data > 300 ? a.setData({
                                cutsum: 300
                            }) : a.setData({
                                cutsum: t.data
                            });
                        },
                        fail: function(t) {
                            wx.showToast({
                                title: "网络连接异常",
                                icon: "loading",
                                duration: 2e3
                            });
                        }
                    });
                });
            },
            fail: function(e) {
                t.getWxLogin(function(e) {
                    console.log(e), wx.request({
                        url: t.url + "addon/Loginlog/Loginlog/gethtbi",
                        data: {},
                        method: "POST",
                        header: {
                            "content-type": "application/x-www-form-urlencoded",
                            Cookie: "PHPSESSID=" + e
                        },
                        success: function(t) {
                            console.log("有：", t), a.setData({
                                totalsum: t.data
                            }), t.data > 300 ? a.setData({
                                cutsum: 300
                            }) : a.setData({
                                cutsum: t.data
                            });
                        },
                        fail: function(t) {
                            wx.showToast({
                                title: "网络连接异常",
                                icon: "loading",
                                duration: 2e3
                            });
                        }
                    });
                });
            }
        });
    },
    Clearprice: function() {
        wx.request({
            url: t.url + "addon/Barginlist/Barginlist/zeroPrice",
            data: {
                negoPrice: 0
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log(t.data);
            }
        });
    },
    BargainTel: function() {
        var a = this.data.contact, e = wx.getStorageSync("userInfo");
        wx.request({
            url: t.url + "addon/Barginlist/Barginlist/bargain",
            data: {
                nickName: e.nickName,
                city: e.city,
                contact: a
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {},
            fail: function(t) {}
        });
    },
    Constract: function(a) {
        var e = this, o = wx.getStorageSync("strpicname"), n = this.data.Price, i = this.data.contact, c = this.data.partAorB, s = wx.getStorageSync("userInfo"), d = this.data.demand, u = this.data.email, r = this.data.htbase;
        if (u && u.length > 0) l = "email";
        if (o && o.length > 0) l = "photo";
        if (r && r.length > 0) var l = this.data.id;
        wx.request({
            url: t.url + "addon/Examhtong/Examhtong/addExam",
            data: {
                nickName: s.nickName,
                city: s.city,
                Amount: n,
                contact: i,
                demand: d,
                partAorB: c,
                strpicname: o,
                formId: a,
                title: "委托审查合同",
                htId: r + "--" + l,
                iTemclass: "委托审查合同",
                sstatus: "接到订单，合同审查中...",
                content: "合同审查中..."
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                e.templateSend(a, t.data), "noPrice" == e.data.Price && e.Clearprice();
            },
            fail: function(t) {
                wx.showModal({
                    title: "提示",
                    content: "当前网络不稳定，创建工单失败，请尽快联系‘合同起草助手’客服",
                    showCancel: !1,
                    success: function(t) {
                        t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                    }
                });
            },
            complete: function(t) {
                wx.removeStorage({
                    key: "strpicname"
                }), wx.removeStorage({
                    key: "Amount"
                });
            }
        });
    },
    wxpay: function() {
        var a = this.data.Price;
        this.data.cutsum;
        if ("undefined" != a && a) {
            wx.showToast({
                title: "正在发起支付",
                icon: "loading",
                duration: 16e3
            });
            var e = this, o = wx.getStorageSync("userInfo"), n = this.data.contact;
            this.data.demand;
            wx.request({
                url: t.url + "addon/Paylists/Paylists/charge",
                data: {
                    Amount: a,
                    nickName: o.nickName,
                    contact: n,
                    itemclass: "委托审查合同"
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    wx.requestPayment({
                        timeStamp: t.data.timeStamp,
                        nonceStr: t.data.nonceStr,
                        package: t.data.package,
                        signType: "MD5",
                        paySign: t.data.paySign,
                        success: function(a) {
                            console.log(a);
                            var o = t.data.package.substr(10);
                            wx.switchTab({
                                url: "../MyCover/MyCover"
                            }), e.Constract(o), e.MailToUs();
                        }
                    }), wx.hideToast();
                },
                fail: function(t) {
                    wx.hideToast(), wx.showToast({
                        title: "无法连接网络",
                        icon: "loading",
                        duration: 2e3
                    });
                }
            });
        } else wx.showModal({
            title: "提示",
            content: "你没有选择价格，请回到界面选择价格！",
            showCancel: !1,
            success: function(t) {
                t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
            }
        });
    },
    templateSend: function(a, e) {
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/templateSend",
            data: {
                itemclass: "委托审查合同",
                id: e,
                formId: a,
                Amount: this.data.Price
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("自动发模板消息", t);
            }
        });
    },
    MailToMe: function(a) {
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/MailToCs",
            data: {
                itemclass: "委托审查合同",
                id: a,
                Amount: this.data.Price
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("发提示邮件给客服人员", t);
            }
        });
    },
    MailToUs: function() {
        var a = wx.getStorageSync("userInfo");
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/MailToUs",
            data: {
                itemclass: "委托审查合同",
                Amount: this.data.Price,
                nickName: a.nickName
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("发提示邮件给客服人员", t);
            }
        });
    },
    backto: function() {
        var t = this.data.From, a = this.data.id, e = this.data.htbase;
        2 == t ? wx.redirectTo({
            url: "../../pages/ExamMy/ExamMy?id=" + a + "&htbase=" + e
        }) : wx.switchTab({
            url: "../Exam/Exam"
        });
    },
    radioChange: function(t) {
        this.setData({
            partAorB: t.detail.value
        });
    },
    pradioChange: function(t) {
        console.log("radioChange信息：", t), this.setData({
            Price: t.detail.value
        });
    },
    bindContactinput: function(t) {
        this.setData({
            contact: t.detail.value
        });
    },
    myHTbi: function() {
        var a = this;
        wx.request({
            url: t.url + "addon/Loginlog/Loginlog/gethtbi",
            data: {},
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("有：", t), a.setData({
                    totalsum: t.data
                }), t.data > 300 ? a.setData({
                    cutsum: 300
                }) : a.setData({
                    cutsum: t.data
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "网络连接异常",
                    icon: "loading",
                    duration: 2e3
                });
            }
        });
    },
    letscutsum: function() {
        var a = this, e = this.data.cutsum;
        wx.request({
            url: t.url + "addon/Sharecard/Sharecard/letscutsum",
            data: {
                cutsum: e
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("有：", t), a.setData({
                    totalsum: t.data
                }), t.data > 300 ? a.setData({
                    cutsum: 300
                }) : a.setData({
                    cutsum: t.data
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "网络连接异常",
                    icon: "loading",
                    duration: 2e3
                });
            }
        });
    }
});